package d0316;

import java.util.concurrent.TimeUnit;

public class Resource2 {
    private Object syncObject1 =new Object();
    public void f() {
        System.out.println(Thread.currentThread().getName() + " not synchronized  f()is running.");
        synchronized (this){
            for(int i=0;i<5;i++){
                System.out.println(Thread.currentThread().getName() + "  synchronized  f()is running.");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public void g() {
        System.out.println(Thread.currentThread().getName() + " not synchronized g()is running.");
        Object syncObject1 = null;
        Object syncObject11;
        synchronized (syncObject1){
            for(int i=0;i<5;i++){
                System.out.println(Thread.currentThread().getName() + "  synchronized  f()is running.");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void main(String[] args) {
        Resource2 resource= new Resource2();
        new Thread(()->resource.f()).start();
        new Thread(()->resource.f()).start();
    }
}

